package com.yurun.service.impl;

import com.yurun.entity.Visitor;
import com.yurun.exception.PersistenceException;
import com.yurun.mapper.VisitorMapper;
import com.yurun.model.dto.VisitLogUuidTime;
import com.yurun.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VisitorServiceImpl implements VisitorService {
    @Autowired
    VisitorMapper visitorMapper;

    @Override
    public void addVisitor(Visitor visitor){
        if(visitorMapper.addVisitor(visitor)!=1){
            throw new PersistenceException("添加用户失败");
        }
    }

    @Override
    public void deleteVisitorById(Long id){
        if(visitorMapper.deleteVisitorById(id)!=1){
            throw new PersistenceException("删除用户失败");
        }
    }

    @Override
    public void updatePVAndLastTimeByUUID(VisitLogUuidTime dto){
        if(visitorMapper.updatePVAndLastTimeByUUID(dto)!=1){
            throw new PersistenceException("根据标识更新访客数量失败");
        }
    }

    @Override
    public int hasUUID(String uuid){
        return visitorMapper.hasUUID(uuid);
    }

    @Override
    public List<Visitor> getVisitorListByDate(String startDate,String endDate){
        return visitorMapper.getVisitorListByDate(startDate, endDate);
    }

    @Override
    public List<String> getNewVisitorIpSourceByYesterDay(){
        return visitorMapper.getNewVisitorIpSourceByYesterDay();
    }
}
